
#ifndef BLOCK_DEVICE_H__
#define BLOCK_DEVICE_H__
#include <stdint.h>
#include "BlockDeviceParam.h"

#define BD_ToSectorAddress(address)	(address & (~(BD_SectorSize - 1)))	

void BD_Lock(void);
void BD_Unlock(void);

int BD_SafeRead(uint32_t address, void* buffer, uint32_t length);
int BD_SafeWrite(uint32_t address, void* buffer, uint32_t length);


//init the block device
void BD_Init(void);
//read data from block device at specif address
/*
@address:  the address of data where read from
@buffer:  memory to strage the data
@length:  the length of data we want to read
*/
int BD_Read(uint32_t address, void* buffer, uint32_t length);

//read data from block device at specif address with cach
/*
@address:  the address of data where read from
@buffer:  memory to strage the data
@length:  the length of data we want to read
*/
int BD_CachRead(uint32_t address, void* buffer, uint32_t length);

//program data to specif address
/*
@address:  the address of data where write to
@buffer:  memory  strage the data
@length:  the length of data we want to write
*/
int BD_Program(uint32_t address, void* buffer, uint32_t length);
//erase sector
/*
@address: the address of sector which we want to erase
*/
int BD_Erase(uint32_t address);

//pre read data in cach
/*
@address: the address of data which we want to cach
*/
int BD_Cach(uint32_t address);


#endif


